package PrjHttpUtils

/*
 * 当心被批处理清理
 */

import (
	"dgo/goutils/utils"
	"net/http"
)

/*
*

	提交保存日志到数据
	time(unixHex),type,lvl,src,msg(jsonescape)\r\n
	/sys/log/add?id=XXX-BDXN&type=QXBASE
*/
func OnHttpLogAdd(w http.ResponseWriter, r *http.Request) {
	appid := r.URL.Query().Get("id")
	apptype := r.URL.Query().Get("type")
	strBody := GetBodyAsString(r)
	cnt, err := ProcessLog2DB(appid, apptype, r.RemoteAddr, strBody)
	if err != nil {
		utils.Log.Warnf("日志数据提交失败:%s", err.Error())
	}
	ResponseJSONValues(w, "code", 0, "cnt", cnt)

}

func RegisterLogHttpFunc() {
	http.HandleFunc("/sys/log/add", WrapHandle(OnHttpLogAdd))

}
